home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / banging_the_metal / qdos / qdos4amiga2 / romsrc / sys / dbugcode_asm < prev    next >
Text File  |  2000-01-03  |  21KB  |  1,027 lines

  1. */beginfile DBUGCODE_asm
  2. ; --------------------------------------------------------------
  3. ; DBUGCODE_asm - QDOS debugging routines
  4. ;          - last modified 26/03/97
  5. ; QDOS-Amiga sources by Rainer Kowallik
  6. ;  ...latest changes by Mark J Swift
  7. ; --------------------------------------------------------------
  8. ;*/beginoverlay
  9.  
  10. ; --------------------------------------------------------------
  11. ; main interrupt server
  12. ; --------------------------------------------------------------
  13. QL_MAIN_INT:
  14.     MOVEM.L    D7/A5/A6,-(A7)
  15.     MOVEA.L    A7,A5
  16.     move.l    a5,d7        ; calculate SV_BASE
  17.     andi.w    #-$8000,d7
  18.     move.l    d7,a6
  19.     move.b    PC_INTR,d7
  20.     lsr.b    #4,d7
  21.     bcs    L00900        ; Vertical blank
  22.     lsr.b    #1,d7
  23.     bcc.s    L003B6
  24.  
  25. ; --------------------------------------------------------------
  26. ; external interrupt
  27.  
  28.     MOVEM.L    D0-D6/A0-A4,-(A7)
  29.     MOVEQ    #0,D0
  30.     MOVEA.L    SV_I2LST(A6),A0    ; pointer to list of
  31.                 ; interrupt 2 drivers
  32.     BSR    EXEC_TSK     ; execute polled task
  33.     MOVEM.L    (A7)+,D0-D6/A0-A4
  34.     BRA.S    L003B6
  35.  
  36. ; --------------------------------------------------------------
  37. ;  Common return for Most system manager traps
  38.  
  39. RET_CLD0:
  40.     MOVEQ    #0,D0
  41. L003A6:
  42. RET_TRAP:
  43.     BTST    #5,$C(A7)    ; was it supervisor mode ?
  44.     BNE.S    L003B6
  45.     TST.W    SV_POLLM(A6)    ; count of poll interrupts
  46.                 ; missed
  47.     BNE    L00936
  48. L003B6:
  49.     MOVEM.L    (A7)+,D7/A5/A6
  50.     RTE
  51.  
  52. ; --------------------------------------------------------------
  53. ; Execute job
  54.  
  55. L00A78:
  56. EXEC_JOB:
  57.     MOVEA.L    $64(A6),A0    ;SV.JBPNT   Pointer to
  58.                 ; current job table entry
  59.     MOVEA.L    (A0),A0
  60.     ADDA.W    #$16,A7        ;*/undomend ADDA.L
  61.                 ;*/note #$16 sign extended long
  62.     MOVE.L    $62(A0),-(A7)
  63.     MOVE.W    $60(A0),-(A7)
  64.     MOVE.L    $1C(A0),$50(A6)    ;SV.TRAPV   Pointer to trap
  65.                 ; redirection table
  66.     MOVEA.L    $5C(A0),A1
  67.     MOVE.L    A1,USP
  68.     MOVEM.L    $20(A0),D0-D7/A0-A6
  69.     RTE
  70.  
  71. ; --------------------------------------------------------------
  72. ;  Execute polled task
  73.  
  74. L00A9E:
  75. EXEC_TSK:
  76.     move.l    d0,-(a7)     ;*/mend MOVE.W   D0,-(A7)
  77. L00AA0:
  78.     MOVEA.L    A0,A3
  79.     adda.l    (a7),a3        ;*/mend ADDA.W   (A7),A3
  80.                 ; word adding causing errors ??
  81.     MOVE.L    A0,-(A7)
  82.     BEQ.S    L00ABC
  83.     MOVE.W    D3,-(A7)
  84.     ANDI.W    #$7F,D3
  85.     MOVEA.L    4(A0),A0     ; A0=address of task
  86.     JSR    (A0)
  87.     MOVE.W    (A7)+,D3
  88.     MOVEA.L    (A7)+,A0
  89.     MOVEA.L    (A0),A0
  90.     BRA.S    L00AA0
  91. L00ABC:
  92.     addq.l    #8,a7        ;*/mend ADDQ.L   #6,A7
  93.     RTS
  94.  
  95. ; --------------------------------------------------------------
  96. ;  TRAP #0 - Enter supervisor mode
  97. ;      - X flag set if already supervisor mode
  98. ; --------------------------------------------------------------
  99. L00318:
  100. TRAP0:
  101.     bset.b    #5,(a7)
  102.     rte
  103.  
  104. ; --------------------------------------------------------------
  105. TRAP1    BSR.S    INI_A5A6
  106.     BRA    DO_TRAP1
  107.  
  108. TRAP2    BSR.S    INI_A5A6
  109.     BRA    DO_TRAP2
  110.  
  111. TRAP3    BSR.S    INI_A5A6
  112.     BRA    DO_TRAP3
  113.  
  114. TRAP4    BSR.S    INI_A5A6
  115.     BRA    DO_TRAP4
  116.  
  117. ; --------------------------------------------------------------
  118. ; Initialize A5 and A6
  119.  
  120. L00336:
  121. INI_A5A6:
  122.     SUBQ.W    #8,A7
  123.     MOVE.L    8(A7),-(A7)
  124.     MOVEM.L    D7/A5/A6,4(A7)
  125.     LEA    4(A7),A5     ; A5 points saved D7,A5,A6
  126.     move.l    a5,d7        ; calculate SV_BASE
  127.     andi.w    #-$8000,d7
  128.     move.l    d7,a6
  129.     MOVEQ    #$7F,D7        ; Registers D7,A5,A6
  130.     AND.L    D7,D0
  131.     RTS
  132.  
  133. ; --------------------------------------------------------------
  134. ;  exceptions that are not handled by user vector
  135. ; --------------------------------------------------------------
  136. BUSERR:
  137.     ori    #$0700,sr    ; mask out all interrupts
  138.  
  139.     bsr    CHK6800X     ; use special 680X0 code?
  140.     bne    TRP0X0
  141.  
  142.     bsr    XTRA
  143.     addq.l    #8,a7        ; dump 68000/008 extra info
  144.  
  145.     bsr    STK_REGS
  146.     moveq    #$08,d7        ; vector offset
  147.  
  148.     bsr    CH_ZERO
  149.     bra    PRTVCTR
  150.  
  151. ; --------------------------------------------------------------
  152. TRPOTHER:
  153.     ori    #$0700,sr    ; mask out all interrupts
  154.  
  155.     bsr    CHK6800X     ; use special 680X0 code?
  156.     bne    TRP0X0
  157.  
  158. ILLEG_INT:
  159.     rte            ; otherwise ignore exception
  160.  
  161. ; --------------------------------------------------------------
  162. ;  special cases of exceptions handled by user vector
  163. ; --------------------------------------------------------------
  164. TAS_EMU:
  165.  
  166. ; Provide emulation of TAS instruction for machines that
  167. ; cannot handle READ-MODIFY-WRITE.
  168.  
  169. ; The user must first replace any TAS (An) / TAS d(An)
  170. ; / TAS $absolute.L by the corresponding line F command
  171. ; (with co-processor ID=7).
  172.  
  173. ; The following code will then emulate the TAS command with
  174. ; the appropriate TST.B ?? and BSET #7,?? instruction pair.
  175.  
  176.     ori    #$0700,sr    ; mask out all interrupts
  177.  
  178.     movem.l    d0-d1/a0-a1,-(a7) ; save regs
  179.  
  180.     move.l    $12(a7),a0    ; addr of last instruction
  181.     move.w    (a0)+,d0     ; get instruction
  182.  
  183.     move.w    d0,d1
  184.     and.w    #$FE00,d0
  185.  
  186.     cmp.w    #$AE00,d0    ; v3.23 or later TAS?
  187.     beq.s    TAS_VALID
  188.  
  189.     cmp.w    #$FE00,d0    ; v3.20-v3.22 TAS?
  190.     beq.s    TAS_VALID
  191.  
  192.     cmp.w    #$F000,d0    ; pre v3.20 TAS?
  193.     bne.s    TAS_SKIP
  194.  
  195. TAS_VALID:
  196.     lea    MODCODE,a1    ; put addr of self-mod code
  197.     move.l    a1,$12(a7)    ; onto stack ready for RTE
  198.  
  199.     move.w    d1,d0        ; restore instruction
  200.     AND.W    #$003F,D0    ; only effective address
  201.  
  202.     MOVE.W    D0,D1
  203.     OR.W    #$4A00,D1    ; make TST.B ? instr.
  204.     move.w    d1,(a1)+     ; put TST instr in place
  205.  
  206.     or.w    #$08C0,d0    ; make BSET #,? instr.
  207.  
  208.     AND.W    #$0038,D1    ; get EA mode
  209.  
  210.     CMP.W    #$0028,D1    ; ARI with displacement ?
  211.     BEQ.S    TAS_ARID
  212.  
  213.     CMP.W    #$0030,D1    ; ARI with index ?
  214.     BEQ.S    TAS_ARID     ; treat as with displacement
  215.                 ; only (should not happen)
  216.  
  217.     CMP.W    #$0038,D1    ; absolute.L ?
  218.     bne.s    TAS_ARI        ; no, treat all other modes
  219.                 ; as ARI
  220.  
  221.     cmp.w    #$08F9,d0    ; really absolute.L ?
  222.     bne.s    TAS_ARID     ; no, treat as ARI+disp.
  223.  
  224. TAS_ABSL:
  225.     move.l    (a0),(a1)+    ; copy long data field
  226.     move.w    d0,(a1)+     ; store BSET instruction
  227.     move.w    #7,(a1)+     ; put bit # to set in place
  228.     move.l    (a0)+,(a1)+    ; copy long data field
  229.     bra.s    TAS_DOIT
  230.  
  231. TAS_ARID:
  232.     move.w    (a0),(a1)+    ; copy word data field
  233.     move.w    d0,(a1)+     ; store BSET instruction
  234.     move.w    #7,(a1)+     ; put bit # to set in place
  235.     move.w    (a0)+,(a1)+    ; copy word data field
  236.     bra.s    TAS_DOIT
  237.  
  238. TAS_ARI:
  239.     move.w    d0,(a1)+     ; store BSET instruction
  240.     move.w    #7,(a1)+     ; put bit # to set in place
  241.  
  242. TAS_DOIT:
  243.     bra    MSR_JMP
  244.  
  245. TAS_SKIP:
  246.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  247.     bra    ILL_INST
  248.  
  249. ; --------------------------------------------------------------
  250. MSR_EMU:
  251.  
  252. ; The following code traps the priviledge exception caused by
  253. ; processing the move sr,<aywhere> instruction in user mode on
  254. ; 680X0 processors, and executes equivalent code.
  255.  
  256. ; The move sr,<anywhere> instruction is not priviledged on the
  257. ; 68000/68008 processors and is used extensively in the pointer
  258. ; environment while in user mode. In later processors the
  259. ; instruction can only be executed in supervisor mode.
  260.  
  261.     ori    #$0700,sr    ; mask out all interrupts
  262.  
  263.     movem.l    d0-d1/a0-a1,-(a7) ; save regs
  264.  
  265.     move.l    $12(a7),a0    ; addr of last instruction
  266.     move.w    (a0)+,d0     ; get instruction
  267.  
  268.     moveq    #0,d1
  269.     move.w    d0,d1
  270.     and.w    #$FFC0,d0
  271.     cmp.w    #$40C0,d0    ; move sr,<?> instruction?
  272.     bne    MSR_SKIP     ; ...no, so exit
  273.  
  274.     move.w    $10(a7),d0    ; get sr
  275.     move.l    usp,a1
  276.     move.w    d0,-(a1)     ; push sr onto user stack
  277.     move.l    a1,usp
  278.  
  279.     lea    MODCODE,a1    ; put addr of self-mod code
  280.     move.l    a1,$12(a7)    ; onto stack ready for RTE
  281.  
  282.     move.w    d1,d0
  283.     andi.w    #$0038,d0    ; get effective address
  284.     beq.s    MSR_DATA     ; branch if move sr,dn
  285.                 ; (special case)
  286.  
  287.     andi.w    #$0007,d1    ; get register
  288.     lsl.w    #6,d1        ; shift
  289.     or.w    d0,d1        ; add in EA
  290.     lsl.w    #3,d1        ; shift
  291.     or.w    #$301F,d1    ; make move.w (a7)+,? instr.
  292.     move.w    d1,(a1)+     ; put instr in place
  293.  
  294.     cmp.w    #$0028,d0    ; ARI with displacement ?
  295.     beq.s    MSR_ARID
  296.  
  297.     cmp.w    #$0030,d0    ; ARI with index ?
  298.     beq.s    MSR_SKIP     ; sorry, can't handle yet!
  299.  
  300.     cmp.w    #$0038,d0    ; absolute.L ?
  301.     bne.s    MSR_ARI        ; no, treat all other modes
  302.                 ; as ARI
  303.  
  304.     cmp.w    #$33DF,d1    ; really absolute.L ?
  305.     bne.s    MSR_JMP        ; no, treat as ARI+disp.
  306.  
  307. MSR_ABSL:
  308.     move.l    (a0)+,(a1)+    ; copy long data field
  309.     bra.s    MSR_JMP
  310.  
  311. MSR_ARID:
  312.     move.w    (a0)+,(a1)+    ; copy word data field
  313.  
  314. MSR_ARI:
  315.     bra.s    MSR_JMP
  316.  
  317. MSR_DATA:
  318.     andi.w    #$0007,d1    ; get register #
  319.  
  320.     move.w    #$48e7,(a1)+    ; make "movem.l dn,-(a7)"
  321.     eori.w    #$f,d1
  322.     moveq    #0,d0
  323.     bset    d1,d0        ; set correct bit for dn
  324.     move.w    d0,(a1)+     ; complete instr
  325.  
  326.     move.w    #$3F6F,(a1)+
  327.     move.l    #$00040002,(a1)+    ; make "move.w 4(a7),2(a7)"
  328.  
  329.     move.w    #$4cdf,(a1)+    ; make "movem.l (a7)+,dn"
  330.     eori.w    #$f,d1
  331.     moveq    #0,d0
  332.     bset    d1,d0        ; set correct bit for dn
  333.     move.w    d0,(a1)+     ; complete instr
  334.  
  335.     move.w    #$548f,(a1)+    ; make "addq.l #2,a7"
  336.  
  337. MSR_JMP:
  338.     move.w    #$4EF9,(a1)+    ; make JMP instruction
  339.     move.l    a0,(a1)+     ; jump behind MSR instr
  340.  
  341. MSR_XIT:
  342.     bsr    CLRALL        ; ...just in case
  343.  
  344.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  345.  
  346.     rte            ; perform operation
  347.  
  348. MSR_SKIP:
  349.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  350.     bra.s    PRIV_ERR
  351.  
  352. ; --------------------------------------------------------------
  353. MOVP_EMU:
  354.     ori    #$0700,sr    ; mask out all interrupts
  355.  
  356.     movem.l    d0-d1/a0-a1,-(a7) ; save regs
  357.  
  358.     move.l    $12(a7),a0    ; addr of last instruction
  359.     move.w    (a0)+,d0     ; get instruction
  360.  
  361.     move.w    d0,d1
  362.     andi.w    #$F138,d0
  363.     cmpi.w    #$0108,d0
  364.  
  365.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  366.     bne    ILL_INST
  367.  
  368.     bsr    STK_REGS
  369. RLOC07    jsr    _moveperipheral-ORG0
  370.     bra    TIDYUP
  371.  
  372. ; --------------------------------------------------------------
  373. ;  Redirect other exceptions thro' possible user table
  374. ; --------------------------------------------------------------
  375. TRAPRDIR:
  376. ADR_ERR:
  377.     BSR.S    TRAPTRAP
  378. ILL_INST:
  379.     BSR.S    TRAPTRAP
  380. ZERO_DIV:
  381.     BSR.S    TRAPTRAP
  382. CHK_INST:
  383.     BSR.S    TRAPTRAP
  384. TRAPV_INst:
  385.     BSR.S    TRAPTRAP
  386. PRIV_ERR:
  387.     BSR.S    TRAPTRAP
  388. TRACE:
  389.     BSR.S    TRAPTRAP
  390. NMI_INT:
  391.     BSR.S    TRAPTRAP
  392. TRAP5:
  393.     BSR.S    TRAPTRAP
  394. TRAP6:
  395.     BSR.S    TRAPTRAP
  396. TRAP7:
  397.     BSR.S    TRAPTRAP
  398. TRAP8:
  399.     BSR.S    TRAPTRAP
  400. TRAP9:
  401.     BSR.S    TRAPTRAP
  402. TRAP10:
  403.     BSR.S    TRAPTRAP
  404. TRAP11:
  405.     BSR.S    TRAPTRAP
  406. TRAP12:
  407.     BSR.S    TRAPTRAP
  408. TRAP13:
  409.     BSR.S    TRAPTRAP
  410. TRAP14:
  411.     BSR.S    TRAPTRAP
  412. TRAP15:
  413.     BSR.S    TRAPTRAP
  414.  
  415. ; --------------------------------------------------------------
  416. ;  default exception/trap table
  417. ; --------------------------------------------------------------
  418. TRAPTAB:
  419.         DC.L    ADRERR-ORG0
  420.         DC.L    ILLINS-ORG0
  421.         DC.L    ZERODV-ORG0
  422.         DC.L    CHKR-ORG0
  423.         DC.L    TRAPVR-ORG0
  424.         DC.L    PRIVR-ORG0
  425.         DC.L    TRACET-ORG0
  426.         DC.L    NMI_NEW-ORG0
  427.         DC.L    TRAPR-ORG0
  428.         DC.L    TRAPR-ORG0
  429.         DC.L    TRAPR-ORG0
  430.         DC.L    TRAPR-ORG0
  431.         DC.L    TRAPR-ORG0
  432.         DC.L    TRAPR-ORG0
  433.         DC.L    TRAPR-ORG0
  434.         DC.L    TRAPR-ORG0
  435.         DC.L    TRAPR-ORG0
  436.         DC.L    TRAPR-ORG0
  437.         DC.L    TRAPR-ORG0
  438.  
  439. ; --------------------------------------------------------------
  440. ;  transfer execution to user or default exception handler
  441. ; --------------------------------------------------------------
  442. TRAPTRAP:
  443.     move.l    a6,-(a7)     ; save a6
  444.     exg    d7,a6        ; save d7
  445.     move.l    a7,d7
  446.     andi.w    #-$8000,d7    ; calc sys vars in a6
  447.     exg    d7,a6        ; restore d7
  448.     tst.l    $50(a6)        ; is there a redirection tbl
  449.     bne.s    TRPCONT1     ; ..yes, use it.
  450.  
  451. RLOC04    move.l    #(TRAPTAB-ORG0)-2*(2),a6 ; default
  452.     bra.s    TRPCONT3
  453. TRPCONT1:
  454.     move.l    $50(a6),a6
  455.     adda.l    #2*($28),a6    ; compensate for
  456.                 ; different table psn
  457. TRPCONT3:
  458. RLOC05    suba.l    #(TRAPRDIR-ORG0),a6
  459. RLOC06    suba.l    #(TRAPRDIR-ORG0),a6
  460.  
  461.     adda.l    4(a7),a6
  462.     adda.l    4(a7),a6     ; address of long vector
  463.     move.l    (a6),4(a7)    ; stack routine address
  464.     move.l    (a7)+,a6     ; restore a6
  465.     rts            ; call routine
  466.  
  467. ; --------------------------------------------------------------
  468. ; Default user exception handlers
  469.  
  470. ADRERR:
  471.     ori    #$0700,sr    ; mask out all interrupts
  472.  
  473.     bsr    CHK6800X     ; use special 680X0 code?
  474.     bne    TRP0X0
  475.  
  476.     bsr    XTRA
  477.     addq.l    #8,a7        ; dump 68000/008 extra info
  478.  
  479.     bsr    STK_REGS
  480.     moveq    #$0C,d7        ; vector offset
  481.  
  482.     bsr    CH_ZERO
  483.     bra    PRTVCTR
  484.  
  485. ; --------------------------------------------------------------
  486. ILLINS:
  487.     ori    #$0700,sr    ; mask out all interrupts
  488.  
  489.     movem.l    d0-d1/a0-a1,-(a7) ; save regs
  490.  
  491.     move.l    $12(a7),a0    ; addr of last instruction
  492.     move.w    (a0)+,d0     ; get instruction
  493.     andi.w    #$F000,d0
  494.  
  495.     cmp.w    #$A000,d0
  496.     beq.s    ALINE        ; branch if A-LINE instruction
  497.  
  498.     cmp.w    #$F000,d0
  499.     beq.s    FLINE        ; branch if F-LINE instruction
  500.  
  501.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  502.  
  503.     bsr    CHK6800X     ; use special 680X0 code?
  504.     bne    TRP0X0
  505.  
  506.     bsr    STK_REGS
  507.     moveq    #$10,d7        ; vector offset
  508.  
  509. ILLINS1:
  510.     bsr    CH_ZERO
  511.  
  512.     LEA    TXTC(PC),A1
  513.     bsr    IOSTRG        ; print err message
  514.  
  515.     move.l    $42(a7),a1
  516.     move.w    (a1),d0
  517.     bsr    HEX10
  518.  
  519.     lea    TXTSPC(pc),a1
  520.     bsr    IOSTRG
  521.  
  522.     bra    PRTVCTR
  523.  
  524. ; --------------------------------------------------------------
  525. ALINE:
  526.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  527.  
  528.     bsr    CHK6800X     ; use special 680X0 code?
  529.     bne    TRP0X0
  530.  
  531.     bsr    STK_REGS
  532.     moveq    #$28,d7
  533.  
  534.     bra    ILLINS1
  535.  
  536. ; --------------------------------------------------------------
  537. FLINE:
  538.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  539.  
  540.     bsr    CHK6800X     ; use special 680X0 code?
  541.     bne    TRP0X0
  542.  
  543.     bsr    STK_REGS
  544.     moveq    #$2C,d7
  545.  
  546.     bra    ILLINS1
  547.  
  548. ; --------------------------------------------------------------
  549. ZERODV:
  550.     ori    #$0700,sr    ; mask out all interrupts
  551.  
  552.     bsr    CHK6800X     ; use special 680X0 code?
  553.     bne    TRP0X0
  554.  
  555.     bsr    STK_REGS
  556.     moveq    #$14,d7        ; vector offset
  557.  
  558.     bsr    CH_ZERO
  559.     bra    PRTVCTR
  560.  
  561. ; --------------------------------------------------------------
  562. CHKR:
  563.     ori    #$0700,sr    ; mask out all interrupts
  564.  
  565.     bsr    CHK6800X     ; use special 680X0 code?
  566.     bne    TRP0X0
  567.  
  568.     bsr    STK_REGS
  569.     moveq    #$18,d7        ; vector offset
  570.  
  571.     bsr    CH_ZERO
  572.     bra    PRTVCTR
  573.  
  574. ; --------------------------------------------------------------
  575. TRAPVR:
  576.     ori    #$0700,sr    ; mask out all interrupts
  577.  
  578.     bsr    CHK6800X     ; use special 680X0 code?
  579.     bne    TRP0X0
  580.  
  581.     bsr    STK_REGS
  582.     moveq    #$1C,d7        ; vector offset
  583.  
  584.     bsr    CH_ZERO
  585.     bra    PRTVCTR
  586.  
  587. ; --------------------------------------------------------------
  588. PRIVR:
  589.     ori    #$0700,sr    ; mask out all interrupts
  590.  
  591.     bsr    CHK6800X     ; use special 680X0 code?
  592.     bne    TRP0X0
  593.  
  594.     bsr    STK_REGS
  595.     moveq    #$20,d7        ; vector offset
  596.  
  597.     bsr    CH_ZERO
  598.     bra    PRTVCTR
  599.  
  600. ; --------------------------------------------------------------
  601. NMI_NEW:
  602.     ori    #$0700,sr    ; mask out all interrupts
  603.  
  604.     bsr    CH_ZERO
  605.     bra    DEAD        ; warm-start into BASIC
  606.  
  607. ; --------------------------------------------------------------
  608. TRACET:
  609.     ori    #$0700,sr    ; mask out all interrupts
  610.  
  611.     bsr    CHK6800X     ; use special 680X0 code?
  612.     bne    TRP0X0
  613.  
  614.     bsr    STK_REGS
  615.     moveq    #$24,d7        ; vector offset
  616.  
  617.     bsr    CH_ZERO
  618.     bra    PRTVCTR
  619.  
  620. ; --------------------------------------------------------------
  621. TRAPR:
  622.     rte            ; ignore undefined TRAP #s
  623.  
  624. ; --------------------------------------------------------------
  625. XTRA:
  626.     movem.l    d0-d7/a0-a6,-(a7) ; save regs
  627.  
  628.     bsr    CH_ZERO
  629.  
  630.     move.w    $40(a7),d0
  631.     lea    TXTR(PC),a1
  632.     btst    #4,d0
  633.     beq.s    XTRA1
  634.     lea    TXTW(PC),a1
  635. XTRA1:
  636.     bsr    IOSTRG        ; R/W
  637.  
  638.     lea    TXTI(PC),a1
  639.     btst    #3,d0
  640.     beq.s    XTRA2
  641.     lea    TXTX(PC),a1
  642. XTRA2:
  643.     bsr    IOSTRG        ; instruction/exception
  644.  
  645.     andi.w    #$7,d0
  646.     lsl.w    #1,d0
  647.     lea    TXTTBL(PC),a1
  648.     move.w    0(a1,d0.w),d0
  649.     lea    TXTUDS(PC),a1
  650.     lea    0(a1,d0.w),a1
  651.     bsr    IOSTRG        ; address space
  652.  
  653.     lea    TXTG(PC),a1
  654.     bsr    IOSTRG
  655.  
  656.     move.l    $42(a7),d0
  657.     bsr    HEX20        ; address
  658.  
  659.     lea    TXTH(PC),a1
  660.     bsr    IOSTRG
  661.  
  662.     move.w    $46(a7),d0
  663.     bsr    HEX10        ; instruction
  664.  
  665.     lea    TXTSPC(pc),a1
  666.     bsr    IOSTRG
  667.  
  668.     movem.l    (a7)+,d0-d7/a0-a6 ; restore regs
  669.  
  670.     rts
  671.  
  672. ; --------------------------------------------------------------
  673. ; 68010 '020 '030 '040 exception handler
  674.  
  675. TRP0X0:
  676.     bsr    STK_REGS
  677.     move.w    $46(a7),d7
  678.     andi.w    #$0FFF,d7    ; vector offset
  679.  
  680. ; find ID for channel zero
  681.  
  682.     bsr    CH_ZERO
  683.  
  684. ; print format code and stack frame
  685.  
  686.     cmp.w    #$24,d7
  687.     beq.s    PRTVCTR        ; skip if TRACE
  688.  
  689.     lea    TXTFMSG(pc),a1    ; "Format code: "
  690.     bsr    IOSTRG
  691.  
  692.     move.w    $46(a7),d0
  693.     rol.w    #4,d0
  694.     andi.w    #$000F,d0
  695.     bsr    HEX04        ; print actual code
  696.  
  697.     lsl.w    #1,d0
  698.     lea    TXTFTBL(PC),a1
  699.     move.w    0(a1,d0.w),d0
  700.     lea    TXT0000(PC),a1
  701.     lea    0(a1,d0.w),a1
  702.     bsr    IOSTRG        ; print stack frame type
  703.  
  704.     lea    TXTSPC(pc),a1
  705.     bsr    IOSTRG
  706.  
  707. ; --------------------------------------------------------------
  708. ; print EXCEPTION VECTOR (now in d7)
  709.  
  710. PRTVCTR:
  711.     cmp.w    #$24,d7
  712.     beq.s    PRTSR        ; skip if TRACE
  713.  
  714.     lea    TXTTMSG(pc),a1
  715.     bsr    IOSTRG        ; print "VECTOR OFFSET "
  716.  
  717.     move.l    d7,d0
  718.     bsr    HEX10
  719.  
  720.     lea    TXTSPC(pc),a1
  721.     bsr    IOSTRG
  722.  
  723. ; print exception - if known
  724.  
  725.     cmp.w    #$30,d7
  726.     bge.s    PRTSR
  727.  
  728.     move.l    d7,d0
  729.     lsr.w    #1,d0
  730.     lea    TXTTTBL(PC),a1
  731.     move.w    0(a1,d0.w),d0
  732.     lea    TXT00(PC),a1
  733.     lea    0(a1,d0.w),a1
  734.     bsr    IOSTRG        ; print exception
  735.  
  736.     lea    TXTSPC(pc),a1
  737.     bsr    IOSTRG
  738.  
  739. ; print Status Register
  740.  
  741. PRTSR:
  742.     LEA    TXTSR(PC),A1
  743.     BSR    IOSTRG
  744.  
  745.     MOVE.W    $40(a7),d0
  746.     BSR    HEX10        ; print SR
  747.  
  748. ; print Program Counter
  749.  
  750.     LEA    TXTPC(PC),A1
  751.     BSR    IOSTRG
  752.  
  753.     MOVE.L    $42(a7),d0
  754.     BSR    HEX20        ; print PC
  755.  
  756.     lea    TXTSPC(pc),a1
  757.     bsr    IOSTRG
  758.  
  759.     move.l    a7,a2        ; address of regs on stack
  760.  
  761. ; print register contents to screen
  762.  
  763.     lea    REGSTK,a3
  764.     move.l    d0,(a3)+
  765.     move.w    (a3)+,d3
  766.  
  767.     lea    TXTREGD(pc),a1
  768.     move.l    a1,d2
  769.     bsr    REGPRT
  770.  
  771.     lea    TXTREGA(pc),a1
  772.     move.l    a1,d2
  773.     bsr    REGPRT
  774.  
  775.     lea    TXTRTN(pc),a1
  776.     bsr    IOSTRG
  777.  
  778.     move.w    $40(a7),-66(a3)
  779.  
  780. ; check for trace
  781.  
  782.     cmp.w    #$24,d7
  783.     beq    NOTDEAD        ; TRACE is not deadly
  784.  
  785. ; exit to BASIC
  786.  
  787. DEAD:
  788.     bclr    #7,JB_RELA6(a4)    ; addresses not a6 relative
  789.  
  790.     move.l    BV_CHBAS(a6),d1    ; get ptr to BASICs # table
  791.     move.l    0(a6,d1.l),d0    ; get ID for #0
  792.     blt.s    DO_WINDO     ; branch if #0 is closed
  793.  
  794.     move.l    d0,a0        ; move ID to a0
  795.     bsr    CH_KEYQ        ; check if chan has a key Q
  796.     bne.s    REL_BAS        ; ...branch if so
  797.  
  798.     move.l    #-1,0(a6,d1.l)    ; otherwise close BASICs' #0
  799.     andi    #$F8FF,sr    ; enable interrupts
  800.     moveq    #IO.CLOSE,d0
  801.     trap    #2        ; close channel
  802.     ori.w    #$0700,sr    ; turn interrupts off
  803.  
  804. DO_WINDO:
  805.     bsr    CH_ZERO        ; and re-open as a CON
  806.     bsr    CH_KEYQ        ; get keyboard Q
  807.  
  808. REL_BAS:
  809.     move.l    a2,SV_KEYQ(a5)    ; make Q current
  810.  
  811.     sf    SV_SCRST(a5)    ; screen status
  812.  
  813.     bclr    #7,JB_RELA6(a4)
  814.  
  815.     move.w    JB_STAT(a4),d0    ; job status (BASIC)
  816.     beq.s    REL_BAS2     ; not suspended
  817.  
  818.     move.b    JB_PRINC(a4),d0    ; priority of BASIC
  819.     bne.s    REL_BAS1
  820.  
  821.     move.b    #$20,JB_PRINC(a4) ; if 0 set to 32
  822.  
  823. REL_BAS1:
  824.     clr.w    JB_STAT(a4)    ; release job
  825.     move.l    JB_HOLD(a4),d0    ; Ptr to byte to be
  826.                 ; cleared when job released
  827.     beq.s    REL_BAS2
  828.  
  829.     movea.l    d0,a3        ; clear this byte
  830.     sf    (a3)
  831.  
  832. REL_BAS2:
  833.     move.l    a6,JB_A6(a4)    ; save BASICs A6
  834.  
  835.     move.l    SV_TRNSP(a5),a3    ; get BASICs A7
  836.     clr.l    -(a3)
  837.     move.l    a3,JB_A7(a4)    ; and save it
  838.  
  839.     lea    L04B54(pc),a2    ; get Basic Warm start address
  840.     move.l    a2,JB_PC(a4)    ; set PC to WARM START address
  841.  
  842.     move.l    a2,-(a3)     ; save return address = basic warm start
  843.  
  844.     move.l    a3,usp
  845.  
  846.     sf    BV_BRK(a6)    ; signal Break to BASIC
  847.  
  848.     move.l    0,a7        ; reset supervisor stack
  849.  
  850. REL_JOB:
  851.     move.l    SV_JBPNT(a5),a3    ; current job table entry
  852.  
  853. JOB_LUP:
  854.     move.l    (a3),a2        ; current jobs' header
  855.     move.l    JB_OWNER(a2),d0    ; owner job
  856.     beq.s    REL_JOB1
  857.  
  858.     swap    d0
  859.     clr.w    d0
  860.     swap    d0
  861.     lsl.l    #2,d0
  862.     add.l    SV_JBBAS(a5),d0
  863.     move.l    d0,a3
  864.     bra.s    JOB_LUP
  865.  
  866. REL_JOB1:
  867.     move.l    a0,d5        ; save ch ID
  868.  
  869.     exg    a5,a6
  870.     bsr    JOBID_ME2
  871.     exg    a5,a6
  872.     move.l    d0,d1
  873.     beq.s    DEADX
  874.  
  875.     moveq    #ERR.NC,d3
  876.     moveq    #MT.FRJOB,d0
  877.     trap    #1        ; remove job
  878.  
  879.     move.l    d5,a0
  880.  
  881. DEADX:
  882.     move.w    #0,sr        ; user mode on
  883.     rts
  884.  
  885. NOTDEAD:
  886.  
  887. ; are next instructions about to be executed in single-trace mode?
  888.  
  889.     btst    #7,$40(a7)
  890.     beq.s    DSKIP        ; ...no, skip disassembly
  891.  
  892. ; if D68K_rext is loaded, print disassembly of next instruction
  893.  
  894.     lea    SV_THINGL(a5),a3    ; start of THING list
  895.  
  896. NEXT_THG:
  897.     move.l    (a3),d0
  898.     beq.s    DSKIP
  899.  
  900.     move.l    d0,a3
  901.  
  902.     cmp.w    #4,$2A(a3)
  903.     bne.s    NEXT_THG
  904.  
  905.     cmp.l    #'d68k',$2C(a3)    ; find d68k 'THING'
  906.     bne.s    NEXT_THG
  907.  
  908.     lea    TXTRTN(pc),a1
  909.     bsr    IOSTRG
  910.  
  911.     move.l    $10(a3),a3    ; address of data area
  912.     addq.l    #8,a3        ; a3 now points to 1st var
  913.  
  914.     move.l    a0,d5        ; save channel ID
  915.     move.l    $42(a7),a0    ; get pc
  916.     move.l    a0,a1        ; set org
  917.     move.l    4(a3),a2     ; address of buffer
  918.     move.l    a2,d4        ; save buffer address
  919.     addq.l    #2,a2
  920.     move.l    (a3),a3        ; address of routine
  921.  
  922.     jsr    (a3)        ; do it.
  923.  
  924.     move.l    d4,a1        ; buffer address
  925.     suba.l    a1,a2
  926.     move.l    a2,d2
  927.     subq.l    #3,d2        ; # bytes to print
  928.     move.w    d2,(a1)
  929.     move.l    d5,a0        ; restore channel ID
  930.     bsr    IOSTRG        ; print it
  931.  
  932.     lea    TXTRTN(pc),a1
  933.     bsr    IOSTRG
  934.  
  935. DSKIP:
  936.     ifnd    serdbg
  937.  
  938. ; wait for key press, then return from exception
  939.  
  940. IPC9KEY:
  941.     andi    #$F8FF,sr    ; enable interrupts
  942.  
  943. IPC9LUP:
  944.     moveq    #MT.IPCOM,d0
  945.     lea    IPC9(pc),a3
  946.     trap    #1
  947.     btst    #6,d1
  948.     bne.s    IPC9X        ; exit if <SPACE> key pressed
  949.  
  950.     cmp.w    #$24,d7
  951.     bne.s    IPC9LUP        ; branch back if not trace
  952.  
  953.     btst    #0,d1
  954.     beq.s    IPC9LUP        ; branch back if not <ENTER> key
  955.  
  956.     andi.w    #$3FFF,$40(a7)    ; clear trace bits
  957.  
  958.     lea    REGSTK,a3
  959.     move.w    $40(a7),4(a3)    ; signal REG store invalid
  960.  
  961.     endif
  962.  
  963. IPC9X:
  964.     move.b    d6,JB_RELA6(a4)    ; restore JOBs' RELA6 flag
  965.  
  966. TIDYUP:
  967.     movem.l    (a7)+,d0-d7/a0-a6
  968.     addq    #4,a7        ; restore regs
  969.  
  970.     rte            ; return from exception
  971.  
  972. ; --------------------------------------------------------------
  973. STK_REGS:
  974.     movem.l    d0-d7/a0-a6,-(a7)
  975.     move.l    $3C(a7),d1    ; get return address
  976.     move.w    $40(a7),d0    ; get sr
  977.     lea    $46(a7),a1    ; get old a7 for supervisor
  978.     btst    #13,d0        ; was user mode ?
  979.     bne.s    STKREG1
  980.     move.l    usp,a1        ; if so, get old usp
  981. STKREG1:
  982.     move.l    a1,$3C(a7)    ; stack old a7
  983.     move.l    d1,-(a7)     ; stack return address
  984.     rts
  985.  
  986. ; --------------------------------------------------------------
  987. REGPRT:
  988.     moveq    #7,d1
  989.  
  990. REGLPD:
  991.     tst.w    d3
  992.     bpl.s    REGPRD
  993.  
  994.     move.l    (a2),d0
  995.     cmp.l    (a3),d0
  996.     beq.s    REGSKP
  997.  
  998. REGPRD:
  999.     move.l    d2,a1
  1000.     bsr    IOSTRG
  1001.  
  1002.     moveq    #7,d0
  1003.     sub.w    d1,d0
  1004.     bsr    HEX04
  1005.  
  1006.     lea    TXTEQU(pc),a1
  1007.     bsr    IOSTRG
  1008.  
  1009.     move.l    (a2),d0
  1010.     bsr    HEX20
  1011.  
  1012.     addq.l    #4,a1
  1013.     bsr    IOSTRG
  1014.  
  1015.     move.l    (a2),(a3)
  1016.  
  1017. REGSKP:
  1018.     addq.l    #4,a2
  1019.     addq.l    #4,a3
  1020.     dbra    d1,REGLPD
  1021.  
  1022.     rts
  1023.  
  1024. ;*/endoverlay
  1025. ; --------------------------------------------------------------
  1026. ;*/endfile
  1027.